﻿using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Common.Enums;

namespace Common.Entities
{
    [DataContract]
    public class UserAccounts
    {
        [DataMember]
        public List<UserAccount> Accounts { get; private set; }

        public UserAccounts()
        {
            Accounts = new List<UserAccount>();
        }

        public void Add(UserAccount userAccount)
        {
            if (userAccount != null)
                Accounts.Add(userAccount);
        }

        public UserAccount GetAccountBySocialNetwork(SocialNetworkName socialNetworkName)
        {
            return (from account in Accounts
                    where account.SocialNetwork.SocialNetworkName == socialNetworkName
                    select account).SingleOrDefault();
        }

        public bool IsNullOrEmpty()
        {
            return Accounts == null || Accounts.Count == 0;
        }
    }
}
